package controller

import (
	"log"
	"mssgserver/constant"
	"mssgserver/net"
	"mssgserver/server/common"
	"mssgserver/server/game/logic"
	"mssgserver/server/game/model"
	"mssgserver/server/game/model/data"
)

var DefaultWarController = &warController{}

type warController struct {
}

func (w *warController) Router(router *net.Router) {
	group := router.Group("war")
	group.AddRouter("report", w.report)
}

/*
*
战报列表
*/
func (w *warController) report(req *net.WsMsgReq, rsp *net.WsMsgRsp) {
	rspObj := &model.WarReportRsp{}
	rsp.Body.Seq = req.Body.Seq
	rsp.Body.Name = req.Body.Name
	rsp.Body.Code = constant.OK
	role, err := req.Conn.GetProperty("role")
	if err != nil {
		log.Println("获取不到role", err)
		return
	}

	rid := role.(*data.Role).RId
	reports, err := logic.DefaultWarService.Report(rid)
	if err != nil {
		rsp.Body.Code = err.(*common.MyError).Code()
		return
	}
	rspObj.List = reports
	rsp.Body.Msg = rspObj
}
